package com.example.demo.controller;

import com.example.demo.model.Commodity;
import com.example.demo.service.ComService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: 宇宙第一帅
 * @Date: 2019/3/27 15:09
 * @Description:
 */
@RestController
@RequestMapping("Commodity")
public class ComController {
    @Autowired
    private ComService comService;

    @PostMapping("insert")
    public String insert(String id, String type, String name, String price, String introduce, String picture){
        if(id == null || id.equals("")){
            return "数据丢失";
        }
        if(type == null || type.equals("")){
            return "丢失";
        }
        if(name == null || name.equals("")){
            return "丢失";
        }
        if(price == null || price.equals("")){
            return "数据丢失";
        }
        if(introduce == null || introduce.equals("")){
            return "数据丢失";
        }
        if(picture == null || picture.equals("")){
            return "数据丢失";
        }
        Integer a = comService.insert(id,type,name,price,introduce,picture);
        if(a == 1){
            return "成功";
        }else{
            return "失败";
        }
    }
    @PostMapping("delete")
    public String delete(String id){
        Integer b = comService.delete(id);
        if(b == 1){
            return "成功";
        }else{
            return "失败";
        }
    }
    @PostMapping("update")
    public String update(Commodity commodity){
        Integer c = comService.update(commodity);
        if(c == 1){
            return "成功";
        }else{
            return "失败";
        }
    }
    @GetMapping("select")
    public List<Commodity> select(){
        return comService.select();
    }
}
